/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.siteEncheres.server.seance;

import API_Systeme.Proxy.API_Systeme_Seance;
import API_Systeme.Proxy.IAPI_Systeme_Proxy;
import API_Systeme.Proxy.Proxy;
import com.google.gwt.user.client.rpc.SerializationException;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import domain.Categorie;
import domain.Observer.Seance;
import domain.Utilisateur;
import java.util.List;
import org.siteEncheres.client.seance.GwtSeance;
import org.siteEncheres.server.GestionSession;

/**
 *
 * @author Francois
 */
public class GwtSeanceImpl extends RemoteServiceServlet implements GwtSeance {

    API_Systeme_Seance apiSeance = new API_Systeme_Seance();
    IAPI_Systeme_Proxy apiProxy =  new Proxy();
    
    @Override
    public void creerSeance(Seance s, int id_utilisateur) throws SerializationException {
        try {
            apiSeance.creerSeance(s, id_utilisateur);
        } catch (Exception ex) {
            throw new SerializationException(ex);
        }
    }
    
    @Override
    public List<Seance> listerSeance(String condition, int nbSeance, int numPage) throws SerializationException {
        try {
            return apiSeance.listerSeance(condition, 100, 1);
        } catch (Exception ex) {
            throw new SerializationException(ex);
        }
    }
    
    @Override
    public void annulerSeance(int id_seance) throws SerializationException {
        return;
    }

    @Override
    public void changerEtatSeance(int id_seance, int etat) throws SerializationException {
        return;
    }

    @Override
    public void finaliserSeance(Seance s) throws SerializationException {
        return;
    }

    @Override
    public void ouvrirSeance(int id_seance) throws SerializationException {
        return;
    }

    @Override
    public void rejoindeSeance(int id_seance, int id_utilisateur) throws SerializationException {
        try {
            apiSeance.rejoindeSeance(id_seance, id_utilisateur);
        } catch (Exception ex) {
            throw new SerializationException(ex);
        }
    }

    @Override
    public void quitterSeance(int id_seance, int id_utilisateur) throws SerializationException {
         try {
            apiProxy.quitterSeance(id_seance, id_utilisateur);
        } catch (Exception ex) {
            throw new SerializationException(ex);
        }
    }

    @Override
    public void posterMessage(int id_seance, int id_utilisateur, String message) throws SerializationException {
        return;
    }

    @Override
    public void encherir(int id_seance, int id_utilisateur, Double prix) throws SerializationException {
        try {
            System.out.println(id_seance + ", " + id_utilisateur + ", " + prix);
            apiProxy.encherir(id_seance, id_utilisateur, prix);
        } catch (Exception ex) {
            throw new SerializationException(ex);
        }
    }

    @Override
    public Utilisateur getUtilisateurEnCours() throws SerializationException {
        Utilisateur u = GestionSession.getUtilisateurEnCours(getThreadLocalRequest());
        return u;
    }
    
    @Override
    public java.util.Date getDateActuelle ()throws SerializationException {
        return java.util.Calendar.getInstance().getTime();
    }

    @Override
    public List<Categorie> getAllCategorie() throws SerializationException {
        try {
            return apiSeance.getAllCategorie();
        } catch (Exception ex) {
            throw new SerializationException(ex);
        }
    }

    @Override
    public boolean participeASeance(int id_seance, int id_utilisateur) throws SerializationException {
        try {
            return apiSeance.participeASeance(id_seance, id_utilisateur);
        } catch (Exception ex) {
            throw new SerializationException(ex);
        }
    }
}
